import { Component, PropsWithChildren } from 'react'
import {View, Text, Image} from '@tarojs/components'
import { AtButton, AtBadge } from 'taro-ui'
import './index.scss'
import headerBg from '../../assets/headerBg.png'
import GlobalFooter from '../../components/GlobalFooter'
import questionResults from '../../data/question_results.json'
import Taro from "@tarojs/taro";
import {getBestQuestionResult} from "../../utils/bizUtils";
import questions from '../../data/question.json'

export default () => {
  const answerList = Taro.getStorageSync('answerList')
  if (!answerList || answerList.length < 1) {
    Taro.showToast({
      title: '答案为空！',
      icon: 'error',
      duration: 3000
    })
  }

  const result = getBestQuestionResult(answerList, questions, questionResults)

  return (
    <View className='resultPage'>
      <View className="at-article__h1 title">{result.resultName}</View>
      <View className="at-article__h2 subtitle">{result.resultDesc}</View>
      <AtButton type="primary" circle className="enterBtn" onClick={
        () => {
          Taro.reLaunch({
            url: '/pages/index/index',
          })
        }
      }>返回主页</AtButton>
      <Image src={headerBg} className="headerBg"/>
      <GlobalFooter />
    </View>
  )
}
